package com.ruoyi.employee.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.HrEmployeeContract;
import com.ruoyi.employee.service.IHrEmployeeContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工合同Controller
 * 
 * @author gy
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/employee/contract")
public class HrEmployeeContractController extends BaseController
{
    @Autowired
    private IHrEmployeeContractService hrEmployeeContractService;

    /**
     * 查询员工合同列表
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrEmployeeContract hrEmployeeContract)
    {
        startPage();
        List<HrEmployeeContract> list = hrEmployeeContractService.selectHrEmployeeContractList(hrEmployeeContract);
        return getDataTable(list);
    }

    /**
     * 导出员工合同列表
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:export')")
    @Log(title = "员工合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrEmployeeContract hrEmployeeContract)
    {
        List<HrEmployeeContract> list = hrEmployeeContractService.selectHrEmployeeContractList(hrEmployeeContract);
        ExcelUtil<HrEmployeeContract> util = new ExcelUtil<HrEmployeeContract>(HrEmployeeContract.class);
        util.exportExcel(response, list, "员工合同数据");
    }

    /**
     * 获取员工合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hrEmployeeContractService.selectHrEmployeeContractById(id));
    }

    /**
     * 新增员工合同
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:add')")
    @Log(title = "员工合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HrEmployeeContract hrEmployeeContract)
    {
        return toAjax(hrEmployeeContractService.insertHrEmployeeContract(hrEmployeeContract));
    }

    /**
     * 修改员工合同
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:edit')")
    @Log(title = "员工合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HrEmployeeContract hrEmployeeContract)
    {
        return toAjax(hrEmployeeContractService.updateHrEmployeeContract(hrEmployeeContract));
    }

    /**
     * 删除员工合同
     */
    @PreAuthorize("@ss.hasPermi('employee:contract:remove')")
    @Log(title = "员工合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hrEmployeeContractService.deleteHrEmployeeContractByIds(ids));
    }
}
